package com.neusoft.exercise;

public class Sort {
	
	//main
	public static void main(String[] args) {
		
		int[] a=new int[] {1,9,2,4,8,6,3};
		print(a);
		bubble(a);
		print(a);
	}
	
	//打印数组
	private static void print(int[] a) {
		for(int i=0;i<a.length;i++) {
			System.out.print(a[i]+" ");
		}
		System.out.println();
	}
	
	
	//冒泡排序
	private static void bubble(int[] arr) {
		
		for(int i=0;i<arr.length;i++) {
			for(int j=0;j<arr.length-1-i;j++) {
				if(arr[j]>arr[j+1]) {
					int temp =arr[j];
					arr[j]=arr[j+1];
					arr[j+1]=temp;
				}
			}
		}
	}
}
